<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>首页_资源共享平台</title>
    <link rel="stylesheet" href="/layui/css/layui.css"/>
    <link rel="stylesheet" href="/css/style.css"/>
</head>
<body>
<div th:include="common/header" class="header-wrapper"></div>
<div th:include="common/adv" class="wrapper"></div>
<div class="container-wrapper">
    <div class="left">
        <div class="data-list">
            <div class="data-list-title">
                <i class="layui-icon layui-icon-search"></i>
                <span class="head">条件检索</span>
            </div>
            <div class="data-search">
                <table>
                    <tr>
                        <td width="80px" style="padding-bottom: 28px;"><label class="data-title-sub">资源类别：</label></td>
                        <td>
                            <ul>
                                <li><a href="/"><span id="t_0">全部</span></a></li>
                                <li th:each="resType:${application.allResTypeList}">
                                    <a th:href="'/res/list?typeId='+${resType.id}" th:title="${resType.name}">
                                        <span th:id="'t_'+${resType.id}" th:text="${resType.name}"></span>
                                    </a>
                                </li>
                            </ul>
                        </td>
                    </tr>
                    <tr>
                        <td>&nbsp;</td>
                    </tr>
                    <tr style="border-top: dashed 1px #e6e6e6;height: 60px;">
                        <td width="80px"><label class="data-title-sub">关键词：</label></td>
                        <td>
                            <form action="/res/search" onsubmit="return submitData()">
                                <div class="layui-col-sm10">
                                    <input type="text" id="q" name="q" autocomplete="off" class="layui-input" style="height: 30px;"/>
                                </div>
                                <div class="layui-col-sm2" style="padding-left: 10px;">
                                    <input type="submit" class="layui-btn layui-btn-radius layui-btn-sm" value="&nbsp;&nbsp;搜&nbsp;&nbsp;索&nbsp;&nbsp;"/>
                                </div>
                            </form>
                        </td>
                    </tr>
                </table>
            </div>
        </div>
        <div class="data-list">
            <div class="data-list-title">
                <i class="layui-icon layui-icon-template-1"></i>
                <span class="head">资源列表</span>
            </div>
            <div class="layui-form">
                <table class="layui-table" lay-skin="line">
                    <colgroup>
                        <col/>
                        <col width="100"/>
                        <col width="80"/>
                        <col width="120"/>
                        <col width="80"/>
                    </colgroup>
                    <thead>
                    <tr>
                        <th>资源名称</th>
                        <th>查看次数</th>
                        <th>上传者</th>
                        <th>上传日期</th>
                        <th>积分</th>
                    </tr>
                    </thead>
                    <tbody>
                    <tr th:each="res:${resList}">
                        <td>
                            <a target="_blank" th:href="'/res/detail/'+${res.id}" th:title="${res.name}"
                               th:text="${#strings.length(res.name)>30} ? ${#strings.substring(res.name,0,31)} : ${res.name}"></a>
                        </td>
                        <td th:text="${res.view}"></td>
                        <td th:text="${res.user.username}"></td>
                        <td th:text="${#dates.format(res.publishDate,'yyyy-MM-dd')}"></td>
                        <td th:text="${res.points}"></td>
                    </tr>
                    </tbody>
                </table>
            </div>
            <div align="center" th:utext="${pageCode}"></div>
        </div>
    </div>
    <div class="right">
        <div class="data-list">
            <div class="data-list-title">
                <i class="layui-icon layui-icon-face-smile-fine"></i>
                <span class="head">每日签到，每日领取3个积分</span>
            </div>
            <div align="center">
                <a onclick="sign()" th:if="${session.currentUser==null or !session.currentUser.sign}">
                    <img style="padding-top: 10px;padding-bottom: 10px;" height="50" alt="用户签到处" src="/images/icon-sign.jpg" />
                </a>
                <div th:if="${session.currentUser!=null and session.currentUser.sign}" style="padding-top: 10px;padding-bottom: 10px;">
                    您今天第 <label style="color: red;" th:text="${session.currentUser.signSort}"></label> 个签到成功！<br />
                    【签到时间: <label th:text="${#dates.format(session.currentUser.signTime,'HH时mm分ss秒')}"></label>】
                </div>
                <p style="padding-bottom: 10px">今日已经有 <label style="color: red;" th:text="${application.signTotal}"></label> 位大佬签到了！</p>
            </div>
        </div>
        <div class="data-list">
            <div class="data-list-title">
                <i class="layui-icon layui-icon-fire"></i>
                <span class="head">热门资源</span>
            </div>
            <div class="data-content">
                <ul>
                    <li th:each="hotRes:${hotResList}">
                        <a target="_blank" th:href="'/res/detail/'+${hotRes.id}" th:title="${hotRes.name}"
                           th:text="${#strings.length(hotRes.name)>20} ? ${#strings.substring(hotRes.name,0,21)} : ${hotRes.name}"></a>
                    </li>
                </ul>
            </div>
        </div>
    </div>
</div>
<div th:include="common/link" class="wrapper"></div>
<div th:include="common/footer" class="footer-wrapper"></div>

<script src="/layui/layui.js"></script>
<script src="/js/common.js"></script>
<script type="text/javascript" th:inline="javascript">
    /*<![CDATA[*/
    let $, layer;
    layui.use(['layer', 'element'], function () {
        $ = layui.jquery,
            layer = layui.layer;

        // 分类选中效果
        let typeId = [[${session.typeId}]];
        $("#" + typeId).css("color", "red");
    });

    function submitData() {
        let q = $("#q").val();
        if(q == "") {
            layer.msg("请输入关键字！");
            $("#q").focus();
            return false;
        }
    }

    function sign() {
        $.get("/user/sign", {}, function (result) {
            if (!result.success) {
                alert(result.errorInfo);
            } else {
                alert("签到成功!");
                window.location.reload();
            }
        }, "json");
    }
    /*]]>*/
</script>
</body>
</html>